 
/******************************************/
/* interaction term model for daily wages */
/*******************************************/
capture program drop wagesinter
program define wagesinter
version 11
syntax, occp(name) 

/********************/
/* Balanced Sample  */
/********************/
use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\select\final.dta", clear

/* keep individuals in the occupation group */
keep if (btime==1 & `occp') | (btime==2 & L.`occp')

/* location in the decile of the initial group distribution */
gen lsnd=ln(sn/dp)
/* residual wages for each year */
quietly: reg lsnd F_* 
predict rlsnd, residuals
/* change in residual wages */
gen drlsnd=D.rlsnd

gen oshift=(`occp'==0 & L.`occp'==1)
keep if btime==2 & L.`occp' & !missing(dimm) & !missing(dimm75)
foreach year in 1982 1991 1999 2007 {
/* winsorize drlsnd */
quietly: sum drlsnd if an==`year', d
replace drlsnd=. if drlsnd>`r(p99)' & an==`year'
replace drlsnd=. if drlsnd<`r(p1)' & an==`year'
}
drop if missing(drlsnd)
drop if missing(basman)
drop if missing(bascom)

/* weight inverse of the size of the group in the CZ */
save temp.dta, replace
gen dummy=1
collapse (sum) nbze = dummy , by(ze an)
gen iw2=1/ nbze
drop nbze

save iw2.dta, replace
use temp.dta, replace
capture drop _merge
joinby ze an using iw2.dta , unm(m)
drop _merge

gen shinter=dimm*lshift
gen shinter75=dimm75*lshift
gen ointer=dimm*oshift
gen ointer75=dimm75*oshift

ivreg2 drlsnd (dimm  = dimm75 ) Y_* [aweight = iw2] , cl(ze) partial(Y_*)
estimates store d1`occp'

ivreg2 drlsnd (dimm shinter  = dimm75 shinter75 ) lshift Y_* [aweight = iw2] , cl(ze) partial(Y_*)
estimates store d2`occp'

estout d1`occp' d2`occp' , cells(b(star fmt(%9.3f)) ///
se(par(`"="("'`")""'))) stats(N r2 rkf) starlevels(* 0.10 ** 0.05 *** 0.01)

 esttab d1`occp' d2`occp' ///
using "C:\Users\Public\Documents\Tab21\Table10_Inter.rtf" /// 
, append title("`occp'")  b(%9.3f) cells(b(star fmt(3)) se(fmt(3) par) ) ///
 star(* 0.10 ** 0.05 *** 0.01)
 

end

capture rm "C:\Users\Public\Documents\Tab21\Table10_Inter.rtf"

wagesinter, occp(all) 
wagesinter, occp(cad) 
wagesinter, occp(tecemp2) 
wagesinter, occp(bc) 
wagesinter, occp(bcnq) 
 

/***********************************************/
/* interaction term for numbers of days worked */
/***********************************************/
capture program drop interdp
program define interdp
version 11
syntax, occp(name) 

/********************/
/* Balanced Sample  */
/********************/
use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\select\final.dta", clear

/* keep individuals in the occupation group */
keep if (btime==1 & `occp') | (btime==2 & L.`occp')

/* location in the decile of the initial group distribution */
gen ldp=ln(dp)
/* residual wages for each year */
quietly: reg ldp F_* 
predict rldp, residuals
/* change in residual wages */
gen drldp=D.rldp

gen oshift=(`occp'==0 & L.`occp'==1)
keep if btime==2 & L.`occp' & !missing(dimm) & !missing(dimm75)
foreach year in 1982 1991 1999 2007 {
/* winsorize drldp */
quietly: sum drldp if an==`year', d
replace drldp=. if drldp>`r(p99)' & an==`year'
replace drldp=. if drldp<`r(p1)' & an==`year'
}
drop if missing(drldp)
drop if missing(basman)
drop if missing(bascom)

/* weight inverse of the size of the group in the CZ */
save temp.dta, replace
gen dummy=1
collapse (sum) nbze = dummy , by(ze an)
gen iw2=1/ nbze
drop nbze

save iw2.dta, replace
use temp.dta, replace
capture drop _merge
joinby ze an using iw2.dta , unm(m)
drop _merge

save temp1.dta, replace
collapse drldp dimm dimm75 Y_*, by(ze an)

/* OLS */
ivreg2 drldp dimm Y_*  , partial(Y_* ) cl(ze)
estimates store bs`occp'ols

/* IV */
ivreg2 drldp (dimm  = dimm75 ) Y_* , partial(Y_* ) cl(ze)
estimates store bs`occp'iv

use temp1.dta, clear
gen shinter=dimm*lshift
gen shinter75=dimm75*lshift
gen ointer=dimm*oshift
gen ointer75=dimm75*oshift

ivreg2 drldp (dimm  = dimm75 ) Y_* [aweight = iw2] , cl(ze) partial(Y_*)
estimates store dp1`occp'

ivreg2 drldp (dimm shinter  = dimm75 shinter75 ) lshift Y_* [aweight = iw2] , cl(ze) partial(Y_*)
estimates store dp2`occp'

 esttab dp1`occp' dp2`occp' ///
using "C:\Users\Public\Documents\Tab21\Table10_Inter.rtf" /// 
, append title("`occp'")  b(%9.3f) cells(b(star fmt(3)) se(fmt(3) par) ) ///
 stats(N ) star(* 0.10 ** 0.05 *** 0.01)
 
end

interdp, occp(all) 
interdp, occp(cad) 
interdp, occp(tecemp2) 
interdp, occp(bc) 
interdp, occp(bcnq) 


 
/************************************/
/* interaction term for annual wage */
/************************************/
capture program drop intersn
program define intersn
version 11
syntax, occp(name) 

/********************/
/* Balanced Sample  */
/********************/
use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\select\final.dta", clear

/* keep individuals in the occupation group */
keep if (btime==1 & `occp') | (btime==2 & L.`occp')

/* location in the decile of the initial group distribution */
gen lsn=ln(sn)
/* residual wages for each year */
quietly: reg lsn F_* 
predict rlsn, residuals
/* change in residual wages */
gen drlsn=D.rlsn

gen oshift=(`occp'==0 & L.`occp'==1)
keep if btime==2 & L.`occp' & !missing(dimm) & !missing(dimm75)
foreach year in 1982 1991 1999 2007 {
/* winsorize drlsn */
quietly: sum drlsn if an==`year', d
replace drlsn=. if drlsn>`r(p99)' & an==`year'
replace drlsn=. if drlsn<`r(p1)' & an==`year'
}
drop if missing(drlsn)
drop if missing(basman)
drop if missing(bascom)

/* weight inverse of the size of the group in the CZ */
save temp.dta, replace
gen dummy=1
collapse (sum) nbze = dummy , by(ze an)
gen iw2=1/ nbze
drop nbze

save iw2.dta, replace
use temp.dta, replace
capture drop _merge
joinby ze an using iw2.dta , unm(m)
drop _merge

save temp1.dta, replace
collapse drlsn dimm dimm75 Y_*, by(ze an)

/* OLS */
ivreg2 drlsn dimm Y_*  , partial(Y_* ) cl(ze)
estimates store bs`occp'ols

/* IV */
ivreg2 drlsn (dimm  = dimm75 ) Y_* , partial(Y_* ) cl(ze)
estimates store bs`occp'iv

use temp1.dta, clear
gen shinter=dimm*lshift
gen shinter75=dimm75*lshift
gen ointer=dimm*oshift
gen ointer75=dimm75*oshift

ivreg2 drlsn (dimm  = dimm75 ) Y_* [aweight = iw2] , cl(ze) partial(Y_*)
estimates store aw1`occp'

ivreg2 drlsn (dimm shinter  = dimm75 shinter75 ) lshift Y_* [aweight = iw2] , cl(ze) partial(Y_*)
estimates store aw2`occp'

 esttab aw1`occp' aw2`occp' ///
using "C:\Users\Public\Documents\Tab21\Table10_Inter.rtf" /// 
, append title("`occp'")  b(%9.3f) cells(b(star fmt(3)) se(fmt(3) par) ) ///
 stats(N ) star(* 0.10 ** 0.05 *** 0.01) 
end

intersn, occp(all) 
intersn, occp(cad) 
intersn, occp(tecemp2) 
intersn, occp(bcq) 
intersn, occp(bcnq) 


 